package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController

public class CourseTeacherController {

    @Autowired
    private CourseTeacherService  courseTeacherService;
    //查询课程教师信息
    @GetMapping("courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> QueryTeacherById(@PathVariable Long courseBaseId) {
        return courseTeacherService.queryTeacherById(courseBaseId, SecurityUtil.getCompanyId());
    }
    /**
     * 新增或修改课程教师信息
     * @param courseTeacherVO
     * @return
     */
    @PostMapping("courseTeacher")
    public CourseTeacherDTO AddOrModify(@RequestBody CourseTeacherVO courseTeacherVO) {
        Long companyId = SecurityUtil.getCompanyId();
        CourseTeacherDTO courseTeacherDTO = CourseTeacherConvert.INSTANCE.vo2dto(courseTeacherVO);

        return courseTeacherService.AddOrModifyTeacher(courseTeacherDTO,companyId);
    }

    //教师删除
    @DeleteMapping("courseTeacher/course/{courseId}/{courseTeacherId}")
    public Boolean deleteTeacher(@PathVariable Long courseId, @PathVariable Long courseTeacherId) {
//        System.out.println(courseId);
//        System.out.println(courseTeacherId);
        Long companyId = SecurityUtil.getCompanyId();
        boolean result = courseTeacherService.deleteTeacherById(courseId, courseTeacherId, companyId);
        return result;
    }
}

